package services

import (
	"zhihu-passion/global"
	"zhihu-passion/internal/models/dao"
)

func CreateArticle(article dao.Article) error {
	return global.Db.Create(&article).Error
}

func BrowseArticle(title string) (list dao.Article, err error) {
	err = global.Db.Where("title = ?", title).First(&list).Error
	return list, err
}

func CreateGood(good dao.Good) error {
	return global.Db.Create(&good).Error
}

func CommentArticle(discuss dao.Discuss) error {
	return global.Db.Create(&discuss).Error
}

func AddReply(reply dao.Reply) error {
	return global.Db.Create(&reply).Error
}

func GoodsList(Content string) (list []*dao.Discuss, err error) {
	err = global.Db.Where("Content like ?", "%"+Content+"%").Order("num desc").Find(&list).Error
	return list, err
}

func AddStatistics(statistics dao.Statistics) error {
	return global.Db.Create(&statistics).Error
}

func Del(articleId int) error {
	return global.Db.Where("articleId = ?", articleId).Delete(dao.Statistics{}).Error
}
